<?php

namespace Admin\Controller;

use Think\Controller;

class LoginController extends CommonController
{
//    public function login()
//    {
//        $this->display();
//    }

    public function out()//退出登录
    {
        session('user', null);
        $this->success('退出成功', U('Login/login'));
    }

    public function checkLogin()//登录验证
    {
        $model_login = D('admin');

        $data['username'] = $_POST['username'];
        $data['password'] = $_POST['password'];
        $rule = where_model()->parseWhere($data);
//        $sql = sprintf();
        $res = $model_login->query("SELECT * FROM admin WHERE $rule ");
        session('user', $res);

        $code = !$res ? self::RET_FAILED : self::RET_SUCCESS;
        $msg = !$res ? '登录成功' : '登录失败';
        $this->ajaxRet($code, $msg);
    }

}